home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: coral.indstate.edu!kalliank
- From: kalliank@coral.indstate.edu
- Subject: Re: while loop problem
- Message-ID: <kalliank.1.314DC1C0@coral.indstate.edu>
- Sender: news@onyx.indstate.edu
- Nntp-Posting-Host: 139.102.86.46
- Organization: Indiana State University
- References: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>
- Date: Mon, 18 Mar 1996 20:04:16 GMT
-
- In article <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca> Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- >Path: onyx.indstate.edu!usenet.ucs.indiana.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!newsfeed.internetmci.com!solaris.cc.vt.edu!news.mathworks.com!uhog.mit.edu!uw-beaver!nntp.cs.ubc.ca!unixg.ubc.ca!news.bc.net!rover.ucs.ualberta.ca!tribune.usask.ca!m
- >ngol.sasknet.sk.ca!canopus.cc.umanitoba.ca!io.UWinnipeg.ca!wsimpson
- >From: Bill Simpson <wsimpson@uwinnipeg.ca>
- >Newsgroups: comp.lang.c
- >Subject: while loop problem
- >Date: Tue, 12 Mar 1996 13:36:41 -0600
- >Organization: The University of Manitoba
- >Lines: 33
- >Message-ID: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>
- >NNTP-Posting-Host: io.uwinnipeg.ca
- >Mime-Version: 1.0
- >Content-Type: TEXT/PLAIN; charset=US-ASCII
-
-
- >Consider the following code fragment:
-
- >y=2000; z=1000;
- >x=0;
- >while(x<=XMAX)
- > {
- > x+=(int) erand(mean);
- > setdot(x,y,z);
- > }
- >
- >It plots a line of dots that are randomly (exponentially) spaced, giving
- >a 1D spatial Poisson process.
- >The problem is that dot x coordinates can only be between 0 and XMAX.
- >The above code will also attempt to plot one point at an x value >XMAX
- >before it terminates.
-
- >Is there a nice way to write the code so it works properly?
-
- >The only way I have thought of is
- >y=2000; z=1000;
- >x=0;
- >while(x<=XMAX)
- > {
- > x+=(int) erand(mean);
- > if(x<=XMAX)
- > setdot(x,y,z);
- > }
-
- >which seems very clumsy since the same test is done twice.
-
- >Thanks very much for any help.
-
- >Bill Simpson
-
- Is This Any Better :-
-
- y=2000; z=1000;
- x=(int) erand(mean);
-
- while(x <= XMAX)
- {
- setdot(x,y,z);
- x += (int) erand(mean);
- }
- Keshav..
-